package com.njuse.jvmfinal.runtimestructure;

import com.njuse.jvmfinal.memory.jclass.AccessFlags;
import com.njuse.jvmfinal.memory.jclass.Field;
import com.njuse.jvmfinal.memory.jclass.JClass;
import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
public class Jobject {
	
private JClass clazz;
private Object[] fields;

public Jobject(JClass clazz) {

	this.clazz=clazz;
	int count=clazz.getInstanceSlotCount();
	this.fields=new Object[count];
	while (clazz!=null) {
	Field[] Fields=clazz.getFields();
	for (int i=0;i<Fields.length;i++) {
		if ((Fields[i].accessFlags&AccessFlags.ACC_STATIC)==0) {
			String des=Fields[i].getDescriptor();
			int position=Fields[i].getPosition();
			switch (des.charAt(0)) {
			  case 'Z':
              case 'B':
              case 'C':
              case 'S':
              case 'I':
              case 'F':
                  this.fields[position]=0;
                  break;
              case 'J':
              case 'D':
                  this.fields[position]=0;
                  this.fields[position+1]=0;
                  break;
             default:
                  this.fields[position]=null;
                  break; 
			}
		}
	}
	clazz=clazz.getSuperClass();
	}
}
}
